package com.practice.springboot_01_zwj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.practice.springboot_01_zwj.entity.FeatureCustomer;
import com.practice.springboot_01_zwj.mapper.FeatureCustomerMapper;
import com.practice.springboot_01_zwj.service.FeatureCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class FeatureCustomerServiceImpl implements FeatureCustomerService {
    @Autowired
    private FeatureCustomerMapper dao;
    @Override
    public PageInfo<FeatureCustomer> selectByCustomerName(String customerName,String customerBelonging, int pageNum, int pageSize) {
        // 1. 参数校验
        if (pageNum < 1) pageNum = 1;
        if (pageSize < 1 || pageSize > 100) pageSize = 20;

        // 2. 启动分页
        PageHelper.startPage(pageNum, pageSize);

        // 3. 处理空字符串和null值
        if (customerName != null && customerName.isEmpty()) {
            customerName = null;
        }


        // 4. 执行查询
        List<FeatureCustomer> networks = dao.selectByCustomerName(customerName,customerBelonging);

        // 5. 返回分页结果
        return new PageInfo<>(networks);
    }
}
